package grape.crm.rest.relationdetail.mvc;

import com.baomidou.mybatisplus.core.metadata.IPage;
import grape.crm.rest.relationdetail.form.RelationDetailListForm;
import grape.crm.service.relationdetail.query.RelationDetailListQuery;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.*;
import com.baomidou.mybatisplus.core.metadata.IPage;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import javax.validation.Valid;
import grape.crm.rest.relationdetail.form.RelationDetailCreateForm;
import grape.crm.rest.relationdetail.form.RelationDetailUpdateForm;
import grape.crm.rest.relationdetail.form.RelationDetailListPageForm;
import grape.crm.rest.relationdetail.vo.RelationDetailVo;
import grape.crm.rest.relationdetail.mapper.RelationDetailWebMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RestController;
import grape.common.rest.mvc.BaseController;
import grape.crm.service.relationdetail.po.RelationDetail;
import grape.crm.service.relationdetail.api.IRelationDetailService;
import java.util.List;
/**
 * <p>
 * 客户关系具体字典 前端控制器
 * </p>
 *
 * @author yangwei
 * @since 2020-09-14
 */
@RestController
@RequestMapping("/crm/relationdetail")
@Api(tags = "客户关系具体字典相关接口")
public class RelationDetailController extends BaseController<RelationDetailVo, RelationDetail> {

    @Autowired
    private RelationDetailWebMapper currentWebMapper;
    @Autowired
    private IRelationDetailService currentService;



     @ApiOperation("添加客户关系具体字典")
     @PreAuthorize("hasAuthority('relationdetail:single:create')")
     @PostMapping
     @ResponseStatus(HttpStatus.CREATED)
     public RelationDetailVo create(@RequestBody @Valid RelationDetailCreateForm cf) {
         RelationDetail po = currentWebMapper.formToPo(cf);
         return super.create(po);
     }

     @ApiOperation("根据ID查询客户关系具体字典")
     @PreAuthorize("hasAuthority('relationdetail:single:queryById')")
     @GetMapping("/{id}")
     @ResponseStatus(HttpStatus.OK)
     public RelationDetailVo queryById(@PathVariable String id) {
         return super.queryById(id);
     }

     @ApiOperation("删除客户关系具体字典")
     @PreAuthorize("hasAuthority('relationdetail:single:deleteById')")
     @DeleteMapping("/{id}")
     @ResponseStatus(HttpStatus.NO_CONTENT)
     public boolean deleteById(@PathVariable String id) {
         return super.deleteById(id);
     }

     @ApiOperation("更新客户关系具体字典")
     @PreAuthorize("hasAuthority('relationdetail:single:updateById')")
     @PutMapping("/{id}")
     @ResponseStatus(HttpStatus.CREATED)
     public RelationDetailVo update(@PathVariable String id,@RequestBody @Valid RelationDetailUpdateForm uf) {
         RelationDetail po = currentWebMapper.formToPo(uf);
         po.setId(id);
         return super.update(po);
     }

    @ApiOperation("不分页查询客户关系具体字典")
    @PreAuthorize("hasAuthority('relationdetail:single:list')")
    @GetMapping("/list")
    @ResponseStatus(HttpStatus.OK)
    public List<RelationDetailVo> list(RelationDetailListForm listForm) {
        RelationDetail po = currentWebMapper.formToPo(listForm);
        RelationDetailListQuery relationDetailListQuery = new RelationDetailListQuery();
        relationDetailListQuery.setPoQuery(po);
        return super.list(relationDetailListQuery);
    }

    @ApiOperation("分页查询客户关系具体字典")
    @PreAuthorize("hasAuthority('relationdetail:single:listPage')")
    @GetMapping("/listPage")
    @ResponseStatus(HttpStatus.OK)
    public IPage<RelationDetailVo> listPage(RelationDetailListPageForm listPageForm) {
         RelationDetail po = currentWebMapper.formToPo(listPageForm);
        RelationDetailListQuery relationDetailListQuery = new RelationDetailListQuery();
        relationDetailListQuery.setPoQuery(po);
        return super.listPage(relationDetailListQuery,listPageForm);
     }

}
